<template>
	<view class="search">
		<view class="search_one">
			<u-icon @click="home" name="arrow-left" color="#000" size="18"></u-icon>
			<view class="input">
				<u--input placeholder="请输入内容" prefixIcon="search" v-model="value"
					prefixIconStyle="font-size: 22px;color: #909399">
				</u--input>
			</view>
			<span @click="what" style="display: inline-block;">搜索</span>
		</view>
		<view class="histy">
			<p class="histy_one">
				<span>历史搜索</span>
				<u-icon @click='shan' name="trash-fill" color="#ddd" size="28"></u-icon>
			</p>
			<view  class="context">
				<span v-for="i in list" :key="i.id"  class="tab">
					{{i.search}}
				</span>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: "",
				list: []
			}
		},
		methods: {
			what(){
				if(this.value==""){
					alert('请输入问题后再提问')
				}else{
					this.$api.lwjpost({
						search:this.value
					}).then((res)=>{
							this.value = ''
					})
					uni.navigateTo({
						url:'/pages/Home/search'
					})
				}
				
			},
			shan(){
				this.list.forEach(item=>{
					// console.log(item.id)
					this.$api.destroy({id:item.id}).then(arr => {
						console.log(arr)
						this.$api.lwjsearch().then(res => {
							this.list = res.data
							console.log(this.list)
						})
					})
				})
			},
			home() {
				uni.switchTab({
					url: '/pages/Home/Home'	
					
				})
			},
		},
		mounted() {
			this.$api.lwjsearch().then(res => {
				this.list = res.data
				console.log(this.list)
			})
		},
		
	}
</script>
<style lang="scss">
	.search {
		width: 100%;
		height: 60upx;

		// background-color: aqua;
		.search_one {
			display: flex;
			align-items: center;
			justify-content: space-around;
		}

		.histy_one {
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
	}

	.tab {
		display: inline-block;
		// width: 50px;
		text-align: center;
		// height: px;
		background-color: #EEEEEE;
	}

	.context{
		display: flex;
		justify-content: space-between;
	}
	.input {
		// background-color: aqua;
		width: 500upx;
	}
</style>
